package cn.wfu.rlrjds.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import org.springframework.security.crypto.codec.Base64;

import sun.misc.BASE64Encoder;

public class Base64Utils {
	public static String encodeBase64File(String path) throws Exception {
		// 将文件转换成字符串
		File file = new File(path);
		FileInputStream inputFile = new FileInputStream(file);
		byte[] buffer = new byte[(int) file.length()];
		inputFile.read(buffer);
		inputFile.close();
		return Method.encodeToString(buffer, Method.NO_WRAP);
	}

	public static void decoderBase64File(String base64Code, String savePath)
			throws Exception {
		// 将字符串转换成文件
		byte[] buffer = Method.decode(base64Code, Method.NO_WRAP);
		FileOutputStream out = new FileOutputStream(savePath);
		out.write(buffer);
		out.close();
	}

}
